package com.jy.servlet;

import com.alibaba.fastjson.JSON;
import com.jy.bean.Consignee;
import com.jy.service.ConsigneeService;
import com.jy.service.impl.ConsigneeSericelmpl;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.omg.PortableInterceptor.INACTIVE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Iterator;
import java.util.List;

public class merchant_Add_MerchandiseServlet extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(merchant_inquire_consigneeServlet.class);
    private ConsigneeService consigneeService;
    public static String merchant_consignee_name="";

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String id = request.getParameter("consignee_id");  request.getParameter("userName");
        String consignee_name = request.getParameter("consignee_name");
        String type = request.getParameter("consignee_type");
        String price = request.getParameter("consignee_price");
        log.debug("price:"+price);
        String image = request.getParameter("consignee_image");

        consigneeService = new ConsigneeSericelmpl();
        Integer consignee_price = 0;
        //如果添加商品的单价不为空就转为Integer类型
        if (price.trim().length() != 0){
            consignee_price = Integer.parseInt(price);
        }
        Boolean favg = consigneeService.insertConsignee(new Consignee(null,consignee_name,type,consignee_price,null,null));
        merchant_consignee_name = consignee_name;
        String data = JSON.toJSONString(favg);

        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        out.println(data);
        log.debug("data:" +data);
    }

    public static void main(String[] args) {
//        try {
//            log.debug(getAdd_product_picture("D:\\wave2003\\Downloads\\q.png",32));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

}
